package com.groupseven.happycampus.controller;

import com.groupseven.happycampus.common.listener.R;
import com.groupseven.happycampus.common.pojo.LittleUser;
import com.groupseven.happycampus.common.pojo.User;
import com.groupseven.happycampus.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @BeLongsProject: happycampus
 * @BeLongsPackage: com.groupseven.happycampus.controller
 * @Author: WRH
 * @CreateTime: 2022-07-27 14:57
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginService loginService;

    @RequestMapping("/managelogin")
    public R<User> login(@RequestParam Map<String,Object> params){
        User user = loginService.login(params);
        if(user !=null){
            return R.success(user);
        }else {
            return R.error("用户名或密码不正确");
        }
    }
    @RequestMapping("/login")
    public R<LittleUser> littlelogin(@RequestParam Map<String,Object> params){
        System.out.println(params.get("username"));
        LittleUser littleUser = loginService.littlelogin(params);
        if(littleUser !=null){
            return R.success(littleUser);
        }else {
            return R.error("用户名或密码不正确");
        }
    }

}
